<? $this -> load -> view('header');?>
<script language="JavaScript">
	function getRoleList(){
			var create="";
		 $.get('<?=$current_module?>/get_user_list', function(data) {
		 
		 	create+='<table class="listing" cellpadding="0" cellspacing="0">'
		 			+'<tr><th>User Name</th>'
					+'<th>Role</th>'
					+'<th>Edit</th>'
					+'<th>Delete</th>'
				+'</tr>';
		 	$.each($.parseJSON(data), function() {
		 		create+="<tr>";
		 		create+="<td>"+this.username+"</td>";	
		 		create+="<td>"+this.name+"</td>";
		 		create+="<td><a href='javascript:getuserdetail("+this.uuid+");\'><img src=\"<?php echo base_url();?>/img/edit-icon.gif\" width=\"16\" height=\"16\" alt=\"edit\">"+"</a></td>";
		 			create+="<td><a href=\"javascript:deleteUser('"+this.uuid+"');\"><img src=\"<?php echo base_url();?>/img/hr.gif\" width=\"16\" height=\"16\" alt=\"edit\">"+"</a></td>";
		 		create+="</tr>";
		 	});
		
		 	$('#dataList').html(create+"</table>");
   		 	
   		 });
	}
	
	function deleteUser(id){
		
	  $.post("<?=$current_module?>/deleteuser", { UUID: id},
		function(data) {
			alert("Delete Complete");
			getRoleList();
		});
	  }
	
	function getuserdetail(id){
		$('#user_info').show();
		 $.get('<?=$current_module?>/getuserdetail',{UUID:id}, function(data) {
		 	 	$.each($.parseJSON(data), function() {
					
		 	 		$('#uid').val(data.UUID);
		 	 		$('#username').val(data.Username);
		 	 		$('#Firstname').val(data.Firstname);
		 	 		$('#Lastname').val(data.Lastname);
		 	 		$('#Password').val(data.Password);
		 	 		$('#Email').val(data.Email);
		 	 		$('#Usertype').val(data.Usertype);
		 	 	
		 	 		if(data.Block==0){
		 	 			$('#Block').attr('checked', false);
		 	 		}else{
		 	 			$('#Block').attr('checked', true);
		 	 		}
		 	 		
		 	 	
		 	 		
		 	 	});
		 });
	}
	
	function addUser(){
		$('#user_info').show();
		
		$('#uid').val("");
		$('#username').val("");
		$('#Firstname').val("");
		$('#Lastname').val("");
		$('#Password').val("");
		$('#Email').val("");
		$('#Usertype').val("");
		$('#Block').attr('checked', true);
	}
	function edituser(){
		$('#user_info').show();
	  if($('#Block').attr('checked')=="checked")
	  	var isBlock = "1";
	  else
	  	var isBlock = "0";
	  
	 
	  $.post("<?=$current_module?>/saveuser", { uid: $('#uid').val()
	  ,username:$('#username').val(),Firstname:$('#Firstname').val(),Lastname:$('#Lastname').val()
	  ,Password:$('#Password').val(),Email:$('#Email').val()
	  ,Block:isBlock,Usertype:$('#Usertype').val()},
		function(data) {
			$('#user_info').hide();
			 alert( "Save Complete");
			 getRoleList();
		});
	}
	
	$(document).ready(function () {
		getRoleList();
		$('#user_info').hide();
	});
</script>

<div id="middle">
	<? $this -> load -> view('setting/left_menu');?>
	<div id="center-column">
		<div class="top-bar">
			<h1>Role Setting</h1>
			<a href="javascript:addUser();" class="button" >Add User</a>
		</div>
		<div class="table">
			<div id="user_info">
				<input type="hidden" id="uid" value="0" />
				  <table class="listing" cellpadding="0" cellspacing="0">
				  	<tr>
				  		<th colspan="2">Add User/Edit</th>
				  	</tr>
                        <tr>
                        	<td style="width:130px;">UserName:</td>
                        	<td align="left"><input type="text" id="username" /></td>
                        </tr>
                        <tr>
                        	<td>Name:</td>
                        	<td><input type="text" id="Firstname" /></td>
                        </tr>
                          <tr>
                        	<td>Lastname:</td>
                        	<td><input type="text" id="Lastname" /></td>
                        </tr>
                         <tr>
                        	<td>Password:</td>
                        	<td><input type="text" id="Password" /></td>
                        </tr>
                         <tr>
                        	<td>Email:</td>
                        	<td><input type="text" id="Email" /></td>
                        </tr>
                         <tr>
                        	<td>Block:</td>
                        	<td><input type="checkbox" id="Block" />Active Account</td>
                        </tr>
                        
                          <tr>
                        	<td>Role:</td>
                        	<td><? echo form_dropdown('Usertype', $role_type,"0","id=Usertype"); ?><div id="roleUser"><section id="Usertype"></section></div></td>
                        </tr>
                        <tr>
                        	<td colspan="2" align="center"><input type="button"  class="button" value="Save" onclick="edituser();" /></td>
                        </tr>
                  </table>
			</div>
			<br /><br />
				<div  id="dataList"></div>
				
		
		</div>
	</div>
	<div id="right-column">
		<strong class="h">Quick Info</strong>
		<div class="box" >
			<span id="user_infor"> </span>
		</div>
	</div>
</div>
<? $this -> load -> view('footer');?>